import csv
import time

import requests

def register(phone, name, department, useremail,x, type, *kwargs):
    url = "http://172.16.60.164/invite/send"

    payload={'phone': phone}
    files=[

    ]
    headers = {
      'Cookie': 'TrainingPlatform-sid=s%3AO9HXXOby8ntZzrOBJ1zN8WcIKFstrp3q.6Kh6KZKH59DBaB5lBSKpFK174JjZIyI6kKpD4hYtU14'
    }
    response = requests.request("POST", url,headers=headers, data=payload, files=files)

    print(response.text)

    # 用户注册
    register_url = "http://172.16.60.164/invite/register"
    payload={'name': name,
    'department': department,
    'userCode': '111111111111111111',
    'userEmail': useremail,
    'phone': phone,
    'code': '123456',
    'pass': 'Aa111111_'}
    files=[
      ('files',('timg.jpg',open('C:/Users/JYJ/Desktop/图片/timg.jpg','rb'),'image/jpeg')),
      ('files',('U盘.jpg',open('C:/Users/JYJ/Desktop/图片/U盘.jpg','rb'),'image/jpeg'))
    ]
    headers = {
      'Cookie': 'TrainingPlatform-sid=s%3AO9HXXOby8ntZzrOBJ1zN8WcIKFstrp3q.6Kh6KZKH59DBaB5lBSKpFK174JjZIyI6kKpD4hYtU14'
    }
    response = requests.request("POST", register_url,headers=headers, data=payload, files=files)
    print(response.text)

    # 创建团队
    if type == "register":
        generate_url = "http://172.16.60.164/invite/generate"

        data = {"competition": "6155628ea7152d493209f737",
        "teamName": department+"团队明策划稿{}".format(x),
        "max": "3",
        "department": department ,
        "teacherName": "wanglaoshi" ,
        "teacherContact": "289743892478",
        "teacherEmail": useremail}
        files=[('files',('timg.jpg',open('C:/Users/JYJ/Desktop/图片/timg.jpg','rb'),'image/jpeg'))]

        res = requests.request('POST', generate_url, headers=headers, data=data, files=files)
        print(res.text)
    elif type == "join":
        join_url = "http://172.16.60.164/invite/join"
        data = {"inviteCode": kwargs}
        res = requests.request('POST', join_url, headers=headers, data=data)
        print(res.text)






with open(r'C:\Users\JYJ\Desktop\userinfo1.csv','r') as a:
    csv_reader = csv.reader(a)
    for row in csv_reader:
        register(row[4], row[0], row[1], row[3], time.time(), "join", row[7])
